Uec3.saleInvoiceItemAddWin = Ext.extend(Ext.UecWindow,{
	constructor:function(config){
		this.initGrid();
		this.initPanelContainer();
		config=Ext.apply(config||{},{items:[this.searchPanel,this.grid]});
		Uec3.saleInvoiceItemAddWin.superclass.constructor.call(this,config);
	},
	initGrid:function(){
		var record = Ext.data.Record.create([
      		{name : 'id',type : 'int'}, 
      		{name : 'companyId',type : 'int'}, 
      		{name : 'customerId',type : 'int'}, 
      		{name : 'code',type : 'string'}, 
      		{name : 'documentType',type : 'int'},
      		{name : 'customerName',type : 'string'}, 
      		{name : 'documentTypeName',type : 'string'}, 
      		{name : 'status',type : 'int'}, 
      		{name : 'receivableCode',type : 'string'}, 
      		{name : 'receivable',type : 'double'}, 
      		{name : 'receivableReceived',type : 'double'},
      		{name : 'receivableUnReceived',type : 'double'}]);
      		
        this.store = new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+'/receivable/base!extList.do'}),
			pruneModifiedRecords : true,
			baseParams : {status:0},
			paramNames : {start : "start",limit : "limit",sort : "sort",dir : "dir"},
			reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, record)
	});
	
	var columnModel = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(), 
		{
		header:'操作',
		width:50,
		xtype:'anchorcolumn',
		dataIndex : 'act',
		items:[{
				text:"选中",
				scope:this,
				permissionId:102,
				handler:this.funSelect
			}]
		},
	    {header : '应付款凭证号',width : 100,dataIndex : 'code'}, 
	    {header : '客户',width : 100,align:"left",dataIndex : 'customerName'}, 
	    {header : '单据类型',width : 75,align:"left",dataIndex : 'documentTypeName'}, 
	    {header : '应收总金额',width : 75,align:"right",dataIndex : 'receivable'}, 
	    {header : '未收金额',width : 75,align:"right",dataIndex : 'unReceived'}, 
	    {header : '已收金额',width : 75,align:"right",dataIndex : 'received'}]);		
	    
	this.grid=new Ext.grid.GridPanel({
			cm : columnModel,
			store : this.store,
			selModel : new Ext.grid.RowSelectionModel({moveEditorOnEnter : true}),
			iconCls : 'icon-grid',
			loadMask : {msg : '数据加载中...'},
			stripeRows : true,
			flex:1,
			autoScroll : true,
			bbar : new Ext.PagingToolbar({
				pageSize : 10,
				store : this.store,
				displayInfo : true,
				style : 'center',
				displayMsg : '第 {0} - {1} 条  共 {2} 条',
				emptyMsg : "没有记录"
			})
		});    
	},
	initPanelContainer:function(){
		this.searchPanel=new Ext.FormPanel({
			frame:true,
			layout:'uec3grid',
    		height:40,
    		layoutConfig:{
    			hGrid:[7,17,7,25],
				vGrid:[100]
		    },
		    items:[
		    {xtype : 'label',text : '模糊查询:'},
		    {xtype : 'textfield',name:'textSearchConditions',emptyText : '多条件可用逗号或者空格隔开!',scope:this,
	         	listeners : {
		        	'specialkey' : function(field, e) {
			    		if (e.getKey() == Ext.EventObject.ENTER) {
						this.search();
						}
					}
				}	
			},
			{xtype : 'button',text : '查询',scope:this,handler:this.search},
			{xtype:'label',text:'可查条件:应付款凭证号,供应商,单据类型'}
		    ]
			
		});
	},
	funSelect:function(grid, rowIndex, colIndex, item, e){
		if(this.params.window){
			var store=this.params.window.saleInvoiceItem_store;
			var record=this.store.getAt(rowIndex);
			var newRecord=this.params.window.getSaleInvoiceItemRecord(record.data,0);
			store.add(newRecord);
			this.close();
		}
	},
	show:function(){
		if(this.params.customerId||this.params.ids){
	    	this.store.baseParams={customerId:this.params.customerId,idsnot:Ext.encode(this.params.idsnot)};
			this.store.load();
    	}
		Uec3.saleInvoiceItemAddWin.superclass.show.call(this);
	}
});


Uec3.saleInvoiceItemAddWindow = Ext.extend(Ext.app.Module, {
	 createWindow : function(params){
	     var windowId=this.id;
   	     if(params&&params.winId){
   	  	     windowId+=Ext.isEmpty(params.winId)?"":"_"+params.winId;
   	     }
         var desktop = this.app.getDesktop(); 
         var win = desktop.getWindowByUecId(windowId);
         if(!win){ 
	         win = desktop.createWindowNoTaskMaxZIndex({
	             uecId: windowId,
	             title: '付款单明细查询',
	             width: 1000,
	           	 height: 500,
	           	 modal:true,
	             shim: false,
	             params:params,
	             animCollapse: false,
	             constrainHeader: true,
	             maximizable: true,
	             layout: "vbox",
	             layoutConfig:{align:'stretch'}
	         },Uec3.saleInvoiceItemAddWin);
         }	 
	     win.show();
   	 }
});
